namespace DataAccess.Base
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using DataAccess.Handlers;

    /// <summary>
    /// Clase DAO base para stored procedures que devuelven un valor escalar.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ProcedureScalarDAO<T> : ProcedureDAO<T>
    {
        public T Execute()
        {
            this.PopulateParameters();

            object result = DataHelper.Current.ExecuteScalar(this.ProcedureName, this.Parameters);

            if ((result == null) || (Convert.IsDBNull(result)))
                return default(T);
            else
                return (T)result;
        }
    }
}